package thread.state;

/**
 * @author 真香
 * @create 2021-06-03 22:14
 */


/**
 *
 * 测试线程的优先级
 *
 *
 */
public class TestPriority {
    public static void main(String[] args){


        System.out.println(Thread.currentThread().getName()+"主线程默认优先级---->"+Thread.currentThread().getPriority());
        MyPriority priority = new MyPriority();
        Thread t1 = new Thread(priority);
        Thread t2 = new Thread(priority);
        Thread t3 = new Thread(priority);
        Thread t4 = new Thread(priority);
        Thread t5 = new Thread(priority);
        Thread t6 = new Thread(priority);


        // 先设置优先级再启动
        t1.start();

        t2.setPriority(1);
        t2.start();

        t3.setPriority(4);
        t3.start();

        // MAX_PRIORITY = 10
        t4.setPriority(Thread.MAX_PRIORITY);
        t4.start();

/*
        t5.setPriority(-1);
        t5.start();

        t6.setPriority(11);
        t6.start();
        */



    }


}


class MyPriority implements Runnable {



    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName()+"---->"+Thread.currentThread().getPriority());
    }
}
